#include <string.h>
#include <stdlib.h>

//#include "usart.h"

int get_host_addr(char pacIP[19], unsigned short *pusPort)
{
	int ret = -1, iLen = 0;
	char acCfg[30] = {0}, acIP[19] = {0}, acPort[6] = {0};
	char *strx = NULL;
	int i = 0, j = 0, p = 0;
	char c = 0, flag = 0;
	*pusPort = 0;
	//iLen = uart1_get_str(acCfg, sizeof(acCfg));
	if(18 < iLen){
		strx=strstr((const char*)acCfg, "host:");// format->"host:47.91.238.235,7385\r\n" , "host:120.24.184.124,8010"
		if(NULL != strx){
			do{
				c = acCfg[i++];
				if(0x0D == c && 2 == flag) {ret = 0; break;}
				if(':' == c && 0 == flag) {flag = 1; continue;}
				if(',' == c && 1 == flag) {flag = 2; continue;}
				if(1 == flag){
					acIP[j++] = c;
					if(j == sizeof(acIP)) break;
				}
				if(2 == flag){
					acPort[p++] = c;
					if(p == sizeof(acPort)) break;
				}	
			}while(c);
		}
	}
	if(0 == ret){
		memcpy(pacIP, acIP, j);
		*pusPort = (unsigned short)atoi(acPort);
	}
	return ret;// 0 success -1 error
}
